473,424 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,424 software developers and data experts.

Duplicate values in drop down list box

I have a bit of a problem and any help would be much appreciated.

Problem: I have two dropdown list boxes with same data(all data
driven).
These are used for two separate entries.
For every entry you cannot choose the same value twice.
For example, I cannot choose for entry 1 the same
value in both selection boxes (gqCategory1Entry1 and
gqCategory2Entry1)

This part works.
The second entry is the problem: When I choose a value for Entry
Two that is the same as in entry one it thinks that "Dubplicate
Divisons have been selected").

WHen in fact these are two separate entries.

Code:
<head>
//Enry number one...no Duplicates
function check_selection(elt){
//check for duplicate selections
var form=elt.form;
var name=elt.name;
var index=elt.selectedIndex
//loop through all form elements
for(var i=0;i<form.length;i++){
var_name=form.elements[i].name;
var_index=form.elements[i].selectedIndex;
if(var_name.substring(0,16)!='gqCategory'){
// if form element is not the current element
// and the division name is the same, raise
//error message
if(var_name!=name&&index!=0&&var_index==index){
alert(var_name);
alert("Duplicate divisions selected! Please choose again.");
elt.selectedIndex=0;
elt.focus();
return false;
}
}
}
return true;
}
</head>

Entry one:
<select name="gqCategory1Entry1" maxlength="48" tabindex = 20
onChange="check_selection(this)" maxlength="48">
<option value="-1"> ---Select a Category---
<option value=1.1 > Division - 1.1 - Internet Sites
<option value=1.2 > Division - 1.2 - Intranet Sites
<option value=1.3 > Division - 1.3 - Interactive communication
</select>
<select name="gqCategory2Entry1" maxlength="48" tabindex = 20
onChange="check_selection(this)" maxlength="48">
<option value="-1"> ---Select a Category---
<option value=1.1 > Division - 1.1 - Internet Sites
<option value=1.2 > Division - 1.2 - Intranet Sites
<option value=1.3 > Division - 1.3 - Interactive communication
</select>
------------
Entry TWO:
<select name="gqCategory1Entry2" maxlength="48" tabindex = 20
onChange="check_selection(this)" maxlength="48">
<option value="-1"> ---Select a Category---
<option value=1.1 > Division - 1.1 - Internet Sites
<option value=1.2 > Division - 1.2 - Intranet Sites
<option value=1.3 > Division - 1.3 - Interactive communication
</select>
<select name="gqCategory2Entry2" maxlength="48" tabindex = 20
onChange="check_selection(this)" maxlength="48">
<option value="-1"> ---Select a Category---
<option value=1.1 > Division - 1.1 - Internet Sites
<option value=1.2 > Division - 1.2 - Intranet Sites
<option value=1.3 > Division - 1.3 - Interactive communication
</select>
Jul 20 '05 #1
1 13982
ma**@idiom.com (marx) writes:
I have a bit of a problem and any help would be much appreciated.

Problem: I have two dropdown list boxes with same data(all data
driven).
You have two select elements with identical options.
These are used for two separate entries.
I.e., you have *four* select elements with identical options,
grouped into two "entries".
For every entry you cannot choose the same value twice.
For example, I cannot choose for entry 1 the same
value in both selection boxes (gqCategory1Entry1 and
gqCategory2Entry1)

This part works.
The second entry is the problem: When I choose a value for Entry
Two that is the same as in entry one it thinks that "Dubplicate
Divisons have been selected").
So the code checks all select elements, not only the ones in the same
"entry".
WHen in fact these are two separate entries.

Code:
<head>
//Enry number one...no Duplicates
function check_selection(elt){
//check for duplicate selections
var form=elt.form;
var name=elt.name;
var index=elt.selectedIndex
//loop through all form elements
for(var i=0;i<form.length;i++){
var_name=form.elements[i].name;
var_index=form.elements[i].selectedIndex;
These variables are not declared, so they become global variables.
No need for that. Put a "var" in front.
if(var_name.substring(0,16)!='gqCategory'){


You only check that they have the same first 16 characters. That misses
the distinction between entries, which is much later in the name.

Example names:
gqCategory1Entry2
gqCategory1Entry1

The entry number is past the first 16 characters, and is never checked.

In case you ever need more than 9 or 10 categories or entries, let's
make this work for any number:

---
function check_selection(elt){
var gqCategoryRE = /^gqCategory(\d+)Entry(\d+)$/;
var index = elt.selectedIndex;
if (index == 0) {return true;} // always legal
var match = elt.name.match(gqCategoryRE);
if (!match) { return; } // not a gqCategory at all.
var category = +match[1];
var entry = +match[2];

var elems = elt.form.elements;
for (var i=0;i<elems.length;i++) {
if (elems[i] == elt) {continue;} // don't test self
match=elems[i].name.match(gqCategoryRE);
if ( match && entry == +match[2] && // same entry
index == elems[i].selectedIndex) { // same selectedIndex
alert("Duplicate division selected! Please choose again.");
elt.selectedIndex = 0;
elt.focus(0);
return false;
}
}
return true;
}
---

Tested in Opera 7 with the supplied select elements.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris Becker | last post by:
This is my attempt to rephrase a question I asked earlier that got no response. I suspect it was my poor/unplanned wording. Here is another attempt: I have a form with some drop down lists. I...
5
by: Rob Wire | last post by:
For the code below, how could I add an item in the drop down lists for both company and location to be an "All" selection that would send to the stored proc. spRptAttachments a value of "%" so...
2
by: R-D-C | last post by:
Hi, got a drop-down list on a windows form in VS.NET2003. In the form load when NOT a postback, we add four values to the drop-down list. These appear in Internet Explorer. When you click...
2
by: macyp | last post by:
I have to pass values from one aspx page to another. The controls I have in the first page are: a textbox, 3 drop down lists, and 2 check boxes, and a submit button. It is a search page, and the...
4
by: gurvar | last post by:
Hi I'm trying to remove duplicate elements from a Drop Down List Fill in VB.net. Following code worked well with vb6. But I'm getting index out of range if I try to translate it to vb.net code...
3
by: Jim McGivney | last post by:
In VWD I have an aspx page with a DropDownList control. The DropDownList is populated from a column from a table in an Access database. If there are duplicate values in the column they are added...
0
by: kajir | last post by:
Hi, I am new at using ASP.Net 2.0. I have various drop down lists on my master page. They refer to an SQL database. I also have a menu on the master page. I can select the values in the drop...
2
by: Jim Gregg | last post by:
Hello all, I am faced with some logic that I am unsure how to handle. Imagine that I am running a WMI query and I am outputting the data into a dynamically created ASP table control. Here is my...
3
by: jcassan | last post by:
Hello folks. I am new to these forums and have something, which has been stumping me for little while. I am using pspell to spellcheck a scrolling textbox (textarea) containing user input. I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.